<%@ page language="java" contentType="application/vnd.ms-excel; name='report_2';charset=utf-8"
    pageEncoding="UTF-8" import="com.java.service.*,java.util.*,com.java.model.UserSession,com.java.util.*,java.text.SimpleDateFormat"%>
<%
response.setHeader("Content-Disposition", "inline; filename=report_3.xls"); // 파일 이름 지정
response.setHeader("Content-Description", "JSP Generated Data");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Excel Download</title>
</head>
<%

UserSession usersession = (UserSession)session.getAttribute("user");
//String ent_id 			= (String)session.getAttribute("ent_id");

String connGroup 	= "";
String user_id 		= "";
if(usersession!=null){
	connGroup 	= CmmUtil.nvl(usersession.getConnGroup(),"0");
	user_id 	= CmmUtil.nvl(usersession.getUser_id(),"");
}

System.out.println("connGroup======>"+connGroup);
System.out.println("user_id======>"+user_id);

String keyword_gb 	= CmmUtil.nvl(request.getParameter("search_gb"),"");
String keyword 		= CmmUtil.nvl(request.getParameter("search_word"),"");
String line_number	= CmmUtil.nvl(request.getParameter("line_number"),"10");
String search_date = CmmUtil.nvl(request.getParameter("search_date"),"");

String present_Year = String.valueOf(GregorianCalendar.getInstance().get(Calendar.YEAR));
//GregorianCalendar에서 1월 return 값이 0이므로 Month에는  1을 더해주어야 함
String present_Month = String.valueOf(GregorianCalendar.getInstance().get(Calendar.MONTH)+1); 
String present_Date = String.valueOf(GregorianCalendar.getInstance().get(Calendar.DATE));

if(present_Month.length() == 1){
	present_Month = "0" + present_Month; //01월,02월 ..... 09월
}

GregorianCalendar g = new GregorianCalendar();
g.add(Calendar.MONTH, 0);

String befor_Month = String.valueOf(g.get(Calendar.MONTH));

if(befor_Month.length() == 1){
	befor_Month = "0" + befor_Month; //01월,02월 ..... 09월
}

if(present_Date.length() == 1){
	present_Date = "0" + present_Date; //01일,02일 ..... 09일
}

//start_dt,close_dt,selected_year,selected_month 의 값에 받아오는 인자가 없을 경우 default로 현재 시간을 Setting
String start_date 		= CmmUtil.nvl(request.getParameter("start_date"),present_Year + befor_Month + present_Date);
String close_date 		= CmmUtil.nvl(request.getParameter("close_date"),present_Year + present_Month + present_Date);


System.out.println("keyword ======> " + keyword);

java.util.Date date = new java.util.Date();
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");     
String today = formatter.format(date); 


if (search_date == null || search_date.equals(""))
	search_date = "";

//페이징 처리 Start
	//페이지 표시정보 받기 혹은 검색입력창
	String curr_page = request.getParameter("curr_page");
	if (curr_page == null || curr_page.equals(""))
		curr_page = "1";
	String one_page = request.getParameter("one_page");
	if (one_page == null || one_page.equals(""))
		one_page = "10";
	String one_group = request.getParameter("one_group");
	if (one_group == null || one_group.equals(""))
		one_group = "10";
	
	String total_count = CmmUtil.nvl(request.getParameter("total_count"),"0");
	
	//페이징 처리 End
	
		
	HashMap map_cnt = new HashMap();
	HashMap map1_cnt = null;
	HashMap map1_cnt2 = null;
	ArrayList list_cnt = new ArrayList();	
	CommonDaoService commonservice_cnt = new CommonDaoService("Com0203lp01Dao_cnt");
	map_cnt.put("connGroup",connGroup);
	map_cnt.put("user_id",user_id);	
	map_cnt.put("start_date",start_date);	
	map_cnt.put("close_date",close_date);	
	list_cnt = (ArrayList)commonservice_cnt.commonDaoMethod(map_cnt);	
	System.out.println(list_cnt);
	
	HashMap map = new HashMap();
	HashMap map1 = null;
	ArrayList list = new ArrayList();
	CommonDaoService commonservice = new CommonDaoService("Com0203lp01Dao");
	map.put("connGroup",connGroup);
	map.put("user_id",user_id);		
	map.put("keyword_gb",keyword_gb);
	map.put("keyword",keyword);	
	map.put("start_date",start_date);
	map.put("close_date",close_date);
	map.put("page_row",total_count);
	map.put("total_row","0");
	map.put("page_no","0");
	
	list = (ArrayList)commonservice.commonDaoMethod(map);
	
	System.out.println(list);
	
	if(list != null){
		if(list.size() > 0){
			total_count = (String)((HashMap)list.get(0)).get("total_row");
			System.out.println("total_count " + total_count);
		}
	}
	
	String app_str="";
	
	int edu_cnt = 0;
	int poi_cnt = 0;
	
	for(int i=0; i<list_cnt.size(); i++){
    	map1_cnt 			= (HashMap)list_cnt.get(i);            	
    	
    	if(map1_cnt.get("gubun").equals("edu")){
    		edu_cnt = edu_cnt + Integer.parseInt((String)map1_cnt.get("cate_cnt"));
    	}else if(map1_cnt.get("gubun").equals("poi")){
    		poi_cnt = poi_cnt + Integer.parseInt((String)map1_cnt.get("cate_cnt"));
    	}
	}
%>

<body>

<form name="excel_frm">
<b></b>
</BR>
</BR>

<table width="760" border="1" cellpadding="2" cellspacing="0" bordercolor="C0C0C0" bordercolordark="#FFFFFF" frame=below >
        	<tr>
            	<td bgcolor="#D3EBD7">수강과정</td>
                <td><%=poi_cnt %>과정</td>    
            </tr>
            <tr>
            	<td bgcolor="#D3EBD7">학습자</td>
                <td><%=edu_cnt %>명</td>    
            </tr>
        </table>
<table><tr><td></td></tr><tr><td></td></tr></table>        
<table width="760" border="1" cellpadding="2" cellspacing="0" bordercolor="C0C0C0" bordercolordark="#FFFFFF" frame=below >
        	<tr>
            	<td bgcolor="#D3EBD7">분류</td>
                <td bgcolor="#D3EBD7">과정수</td>
                <td bgcolor="#D3EBD7">학습자</td>  
            </tr>
<%
for(int i=0; i<list_cnt.size(); i++){
	map1_cnt 			= (HashMap)list_cnt.get(i);            	
	
	edu_cnt = 0;
	poi_cnt = 0;	
	
	if(map1_cnt.get("gubun").equals("poi")){
		poi_cnt = Integer.parseInt((String)map1_cnt.get("cate_cnt"));	
	
		for(int j=0; j<list_cnt.size(); j++){
			map1_cnt2 			= (HashMap)list_cnt.get(j);   
			
			if(map1_cnt2.get("gubun").equals("edu") && map1_cnt2.get("cate_nm").equals(map1_cnt.get("cate_nm"))){
				edu_cnt = Integer.parseInt((String)map1_cnt2.get("cate_cnt"));
				//System.out.println("==============================>"+map1_cnt2.get("cate_nm"));
			}
		}
		
%>
            <tr>
            	<td class="table_td2Line"><%=map1_cnt.get("cate_nm") %></td>
                <td><%=poi_cnt %>과정</td>
                <td><%=edu_cnt %>명</td>    
            </tr>
<%
	}
}
%>
            
</table>
<table><tr><td></td></tr><tr><td></td></tr></table>

<table width="760" border="1" cellpadding="2" cellspacing="0" bordercolor="C0C0C0" bordercolordark="#FFFFFF" frame=below >
                  <tr>
                    <td bgcolor="#D3EBD7">번호</td>
                    <td bgcolor="#D3EBD7">과정명</td>
                    <td bgcolor="#D3EBD7">성명</td>
                    <td bgcolor="#D3EBD7">수강기간</td>
                    <td bgcolor="#D3EBD7">신청일자</td>
                    <td bgcolor="#D3EBD7">상태</td>
                    <td bgcolor="#D3EBD7">비고</td>
                  </tr>
			<%for(int i=0; i<list.size(); i++){
            	map1 			= (HashMap)list.get(i);            	
            	
            	if(map1.get("approval_yn").equals("Y")){
            		app_str = "승인";
            	}else if(map1.get("cancel_yn").equals("Y")){
            		app_str = "취소";
            	}else{
            		app_str = "신청중";
            	}
			%>
                  <tr>
                    <td><%=map1.get("r_num") %></td>
                    <td><%=map1.get("poi_nm") %></td>
                    <td><%=map1.get("login_nm") %></td>
                    <td><%=map1.get("std_app_dt") %></td>
                    <td><%=CmmUtil.nvl((String)map1.get("app_dt") ,"") %></td>
                    <td class="text21p"><%=app_str %></td>
                    <td><%=CmmUtil.nvl((String)map1.get("repl_dt"),"") %></td>
                  </tr>
			<%} %>
                  
</table>   



</form>

</body>
</html>
